package com.fingard.dsp.bank.directbank.bocom13.util;

import com.alibaba.fastjson.JSONObject;
import com.fingard.FGBiz;
import com.fingard.db.JDBCHelper;
import com.fingard.diagnostics.LogHelper;
import oracle.sql.DATE;

import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SeqNumUtil {
    public static boolean saveSendDate(JSONObject jsonObject, StringBuilder p_sb) {
        if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
            try {
                Connection dbConn = null;
                try {
                    dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();
                    String sqlInsert = "insert into t_signnotify(URID,ASKNUMBER,APPORGID,ISPRIVATE,ISBATCH,BANKID,ACCOUNTNUMBER,ACCOUNTNAME,SIGNNO,CERTTYPE,CELLPHONE,CERTNUMBER,ACCOUNTTYPE,CVV2,EXPIREDDATE,LGLREPNM,LGLREPIDTP,LGLREPIDNO,SOURCENOTECODE,POLICYNO,DISABLEDATE,SINGLELIMIT,LIMITPERIODUNIT,MAXCNTLIMIT,NOTEMONEY,INSUREID,INSURENAME)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    JDBCHelper.update(dbConn, sqlInsert, new Object[]{null, jsonObject.getString("RdSeq"),jsonObject.getString("CorpEntity"),jsonObject.getString("PrivateFlag"),jsonObject.getString("BatchFlag"),jsonObject.getString("OppBank"),
                            jsonObject.getString("OppAct"),jsonObject.getString("OppActName"),jsonObject.getString("SignNo"),jsonObject.getString("CertType"),jsonObject.getString("CellPhone"),jsonObject.getString("CertNumber"),
                            jsonObject.getString("CardType"),jsonObject.getString("CVV2"),jsonObject.getString("ExpiredDate"),jsonObject.getString("LGL_Name"),jsonObject.getString("LGL_NameLGL_Name"),jsonObject.getString("LGL_CertNumber"),
                            jsonObject.getString("SourceNoteCode"),jsonObject.getString("PolicyNo"),jsonObject.getString("DisableDate"),jsonObject.getString("SingleLimit"),jsonObject.getString("LimitPeriodUnit"),jsonObject.getString("MaxCountLimit"),
                            jsonObject.getString("NoteMoney"),jsonObject.getString("InsureID"),jsonObject.getString("InsureName")});
                    return true;
                } catch (Exception ex) {
                    p_sb.append(LogHelper.getStackTrace(ex));
                    ex.printStackTrace();
                } finally {
                    if (dbConn != null) {
                        dbConn.close();
                    }
                }
            } catch (Exception ex) {
                p_sb.append(LogHelper.getStackTrace(ex));
                ex.printStackTrace();
            }
        } else {
            p_sb.append("数据库连接未配置或有误");
        }
        return false;
    }

    public static boolean updateSendDate(String asknumber, StringBuilder p_sb) {
        if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
            try {
                Connection dbConn = null;
                try {
                    dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();
                    String sqlInsert = "UPDATE t_signnotify SET PUSHSTATUS='1' WHERE ASKNUMBER=?";
                    JDBCHelper.update(dbConn, sqlInsert, new Object[]{asknumber});
                    return true;
                } catch (Exception ex) {
                    p_sb.append(LogHelper.getStackTrace(ex));
                    ex.printStackTrace();
                } finally {
                    if (dbConn != null) {
                        dbConn.close();
                    }
                }
            } catch (Exception ex) {
                p_sb.append(LogHelper.getStackTrace(ex));
                ex.printStackTrace();
            }
        } else {
            p_sb.append("数据库连接未配置或有误");
        }
        return false;
    }

    public static HashMap<String, String> getSendDate(String tmpSeqID) throws Exception {
        if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
            HashMap<String, String> retMap = new HashMap<String, String>();
            Connection dbConn = null;
            try {
                dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();

                String sqlSelect = "select ASKNUMBER, pushstatus from t_signnotify where ASKNUMBER=?";
                List<Map<String, Object>> seqList = JDBCHelper.execQuery(dbConn, sqlSelect, new Object[]{tmpSeqID});
                if (seqList != null && seqList.size() > 0) {
                    for (Map<String, Object> seqMap : seqList) {
                        retMap.put(String.valueOf(seqMap.get("ASKNUMBER")), String.valueOf(seqMap.get("pushstatus")));
                    }
                }
                return retMap;
            } catch (Exception ex) {
                throw (ex);
            } finally {
                if (dbConn != null) {
                    dbConn.close();
                }
            }
        } else {
            throw new Exception("数据库连接未配置或有误");
        }
    }
}
